package sanrenxing.dayEnd.backRepertoryTotal.service.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sanrenxing.dayEnd.backRepertoryTotal.dao.SettingOfSecuritiesDao;
import sanrenxing.dayEnd.backRepertoryTotal.domain.SettingOfSecurities;
import sanrenxing.dayEnd.backRepertoryTotal.service.SettingOfSecuritiesBiz;

import java.util.HashMap;
import java.util.List;

/**
 * 功能：券商业务层接口实现类
 * 编写者：蒋玲苹
 * 日期：
 * 版本：1.0
 */
@Service
public class SettingOfSecuritiesBizImpl implements SettingOfSecuritiesBiz {
    //定义数据层接口
    @Autowired
    private SettingOfSecuritiesDao settingOfSecuritiesDao;
    /**
     * 添加数据
     * @param settingOfSecurities
     * @return 0:添加失败,1:添加成功
     */
    @Override
    public int add(SettingOfSecurities settingOfSecurities) {
        return settingOfSecuritiesDao.add(settingOfSecurities);
    }

    /**
     * 删除数据
     * @param stockIds
     * @return 删除影响的行数(0 : 删除失败, 1 : 删除成功)
     */
    @Override
    public int delete(String stockIds) {
        //判断是否为批量删除
        if(stockIds.contains(",")){
            //对编号按“，”分割
            String[] strs=stockIds.split(",");
            //循环删除
            for(String str:strs){
                //调用方法删除
                settingOfSecuritiesDao.delete(str);
            }
            //返回1
            return 1;
        }
        return settingOfSecuritiesDao.delete(stockIds);
    }

    /**
     * 修改数据
     * @param settingOfSecurities
     * @return 0:修改失败,1:修改成功
     */
    @Override
    public int update(SettingOfSecurities settingOfSecurities) {
        return settingOfSecuritiesDao.update(settingOfSecurities);
    }

    /**
     * 查询所有数据
     * @param settingOfSecurities
     * @param row
     * @param page
     * @return
     */
    @Override
    public List<SettingOfSecurities> queryAll(SettingOfSecurities settingOfSecurities, int row, int page) {
        HashMap<String,Object> map=new HashMap<>();
        map.put("settingOfSecurities",settingOfSecurities);
        map.put("start",page);
        map.put("end",(page+row));
        return settingOfSecuritiesDao.queryAll(map);
    }

    /**
     * 统计记录数
     *
     * @param settingOfSecurities@return 记录行数据
     */
    @Override
    public int count(SettingOfSecurities settingOfSecurities) {
        return settingOfSecuritiesDao.count();
    }
}
